package com.learn.russianRoulette.entity;

public class role {
    private String roleName;
    private int health;

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    public int getHealth() {
        return health;
    }
    public void setHealth(int health) {
        this.health = health;
    }

    public String getRoleName() {
        return roleName;
    }
    public void shot(role role1, role role2, int[] bullets, int flag) {
        if(bullets[flag]==1){
            role2.health--;
            System.out.println("嘣！实弹爆头！！！");
            pauseForOneSecond(1.0);
            if (role1==role2){
                System.out.println(role1.getRoleName()+"开枪打死了自己\n");
            }
            else {
                System.out.println(role1.getRoleName()+"开枪打死了"+role2.getRoleName()+"\n");
            }
            pauseForOneSecond(1.0);
        }
        else {
            System.out.println("咔！空弹！\n");
            pauseForOneSecond(1.0);
        }
    }
    public static void pauseForOneSecond(double second) {
        // 将秒转换为毫秒，因为Thread.sleep方法需要毫秒参数
        second = second * 1000;
        try {
            // 使当前线程睡眠指定的毫秒数
            Thread.sleep((int)second);
        } catch (InterruptedException e) {
            // 当线程被中断时，捕获InterruptedException并打印堆栈跟踪
            e.printStackTrace();
        }
    }
}
